import { getAreaList } from '@/api/modules/base.js'
export default {
  data() {
    return {
      showAreaPick: false,
      areaSimplify: true, // 精简模式，只拿到省份
      originAreaPick: [],
      currentAreaPick: [
        [],
        [],
        []
      ]
    }
  },

  computed: {
  },

  async mounted() {
    const response = await getAreaList();
    const data = response;
    if (this.isShowAllArea) {
      const all = {
        children: [{
          label: "",
          value: '',
          children: [{
            label: "",
            value: '',
          }]
        }],
        label: "全国",
        value: ''
      }
      data.unshift(all);
    }

    this.currentAreaPick.splice(0, 1, data);
    console.log(this.currentAreaPick,response);

    // 精简版移除后两级
    if (this.areaSimplify) {
      this.currentAreaPick.splice(1, 1)
      this.currentAreaPick.splice(1, 1)
      return
    }
    this.currentAreaPick.splice(1, 1, this.currentAreaPick[0][0].children);
    this.currentAreaPick.splice(2, 1, this.currentAreaPick[1][0].children);
  },

  methods: {
    changeAreaHandler(e) {
      if (this.areaSimplify) {
        return 
      }
      const {
        columnIndex,
        value,
        index,
        // 微信小程序无法将picker实例传出来，只能通过ref操作
        picker = this.$refs.uPicker
      } = e;
      for (let i = columnIndex + 1; i < 3; i++) {
        // 下一个起算跟 上一个的第一个
        const item = i === columnIndex + 1 ? value[i - 1].children : this.currentAreaPick[i - 1][0].children;
        // debugger
        picker.setColumnValues(i, item);
        this.currentAreaPick.splice(i, 1, item);
      }
    }
  },
}